﻿using System.Windows.Forms;
using System.Collections;
using System;

namespace FTTXImportUtility.Utility
{
    static class ListBoxUtility
    {
        public static void SetDataSource(this ListBox listBox, ICollection collection)
        {
            listBox.BeginUpdate();

            ArrayList ar = new ArrayList(collection);

            listBox.Items.AddRange(ar.ToArray());

            listBox.EndUpdate();
        }

        public static void SetDataSource(this ListBox listBox, ICollection collection, string displayMember, string valueMember)
        {
            SetDataSource(listBox, collection);
            listBox.DisplayMember = displayMember;
            listBox.ValueMember = valueMember;
        }

        public static void SetDataSource(this ListBox listBox, ICollection collection, string displayMember, string valueMember, bool AppendIems)
        {
            if (!AppendIems) listBox.Items.Clear();
            SetDataSource(listBox, collection, displayMember, valueMember);
        }
    }
}
